﻿
//Wap显示的主页面
$(function () {
    $.ajax({
        type: "get",
        url: ApiUrl + "api/Personal/WapShow",
        data: { S_account: '张三' },
        //contentType: 'application/json',
        success: function (data) {
            $("#Tosurvey").empty();
            $("#Stayaround").empty();
            $("#Havesurvey").empty();
            $(data).each(function (i, item) {
                if (item.P_state == 0) //0:待约勘，1:待查勘, 2:已查勘 
                {
                    var li = '<li style="height:80px">'
                    + '<a href="detail.html?' + item.P_ReportNumber + '">'
                    + '<dl class="mq_word" style="left:0px">'
                    + '<dd class="mq_com_n">'
                    + '报告编号：' + item.P_ReportNumber + ''
                    + '</dd>'
                    + '<dd>'

                    + '地址：' + item.P_located + ''
                    + '</dd>'
                    + '<dd>'
                    + '联系人：' + item.P_linkman + ''
                    + '</dd>'
                    + '<dd>'
                    + '联系人电话：' + item.P_phone + ''
                    + '</dd>'
                    + '</dl>'
                    + '</a>'
                    + ' </li>';

                    $("#Stayaround").append(li);
                }
                if (item.P_state == 1) //0:待约勘，1:待查勘, 2:已查勘 
                {
                    var li1 = '<li style="height:80px">'
                                 + '<a href="detail.html?' + item.P_ReportNumber + '">'
                                 + '<dl class="mq_word" style="left:0px">'
                                 + '<dd class="mq_com_n">'
                                 + '报告编号：' + item.P_ReportNumber + ''
                                 + '</dd>'
                                 + '<dd>'
                                 + '地址：' + item.P_located + ''
                                 + '</dd>'
                                 + '<dd>'
                                 + '联系人：' + item.P_linkman + ''
                                 + '</dd>'
                                 + '<dd>'
                                 + '联系人电话：' + item.P_phone + ''
                                 + '</dd>'
                                 + '</dl>'
                                 + '</a>'
                                 + ' </li>';

                    $("#Tosurvey").append(li1);
                }
                if (item.P_state >= 2) //0:待约勘，1:待查勘, 2:已查勘  //2016年11-21修改 手机端状态大于等于2的为已查勘 
                {
                    var li2 = '<li style="height:80px">'
                                   + '<a href="detail.html?' + item.P_ReportNumber + '">'
                                   + '<dl class="mq_word" style="left:0px">'
                                   + '<dd class="mq_com_n">'
                                   + '报告编号：' + item.P_ReportNumber + ''
                                   + '</dd>'
                                   + '<dd>'
                                   + '地址：' + item.P_located + ''
                                   + '</dd>'
                                   + '<dd>'
                                   + '联系人：' + item.P_linkman + ''
                                   + '</dd>'
                                   + '<dd>'
                                   + '联系人电话：' + item.P_phone + ''
                                   + '</dd>'
                                   + '</dl>'
                                   + '</a>'
                                   + ' </li>'

                    $("#Havesurvey").append(li2);
                }


            })
        },
        error: function (e) {
            layer.tips('服务器连接异常', '#Hidden1');
        },
        complete: function () {
        }
    })


})
//约没约成
function updatedetail() {
    var radio = $(".ds:checked").attr("id");
    var uri = document.location.search;//接收页面传值
    var i = uri.lastIndexOf("?") + 1;  //获取问号前面的值
    var P_ReportNumber = uri.substr(i);//截取问号前面的值
    var P_cause = $("#P_cause").val();
    if (radio == "Yes") {
        $.ajax({
            type: "get",
            url: ApiUrl + "api/Personal/UpdateP_ReportNumberyes",
            data: {
                P_ReportNumber: P_ReportNumber,
                P_cause: P_cause
            },
            //contentType: 'application/json',
            success: function (data, status) {
                if (data == true) {

                    layer.msg('保存成功!', { icon: 1, time: 1000 });
                }
                else {
                    layer.msg('保存失败!', { icon: 2, time: 1000 });
                }

            },
            error: function (e) {
                layer.msg('服务器连接超时!', { icon: 2, time: 1000 });
            },
            complete: function () {

            }
        })
    }
    if (radio == "NO") {
        $.ajax({
            type: "get",
            url: ApiUrl + "api/Personal/UpdateP_ReportNumberNO",
            data: {
                P_ReportNumber: P_ReportNumber,
                P_cause: P_cause
            },
            //contentType: 'application/json',
            success: function (data, status) {
                if (data == true) {
                    layer.msg('保存成功!', { icon: 1, time: 1000 });
                }
                else {
                    layer.msg('保存失败!', { icon: 2, time: 1000 });
                }

            },
            error: function (e) {

                layer.msg('服务器连接超时!', { icon: 2, time: 1000 });
            },
            complete: function () {

            }
        })
    }
}
//点击查询查询出房屋的信息
function search() {
    var keyword = $("#keyword").val();
    $.ajax({
        type: "get",
        url: ApiUrl + "api/Personal/searchbyP_located",
        data: {
            C_project: keyword
        },
        success: function (data, status) {

            $("#CommunityShow").empty();
            $(data).each(function (i, item) {
                var lis = "<li>"
                              +"<a href=\"#\" onclick=\"Import('" + item.P_ReportNumber + "')\">"
                              +"  <dl>"
                              +"      <dt>" + item.C_project +"</dt>"
                              +"    <dd>"
                              + "      " + item.P_located + ""
                              +"    </dd>"
                              +"    <dd class=\"area\">"
                              + "      " + item.I_Buildingafew + "号楼"
                              +"    </dd>"
                              +" </dl>"
                              +" </a>"
                              + "</li>";
                $("#CommunityShow").append(lis);
            })

        },
        error: function (e) {
            layer.msg('服务器链接超时!', { icon: 2, time: 5000 });
        },
        complete: function () {
        }
    })

}
//导入信息
function Import(P_ReportNumber11) {
    if (layer.confirm('确定要数据复用吗?', { icon: 1 }))
    {
        //小区的数据回填
        $.ajax({
            type: "get",
            url: ApiUrl + "api/Community/SelectByid",
            data: {
                P_ReportNumber: P_ReportNumber11
            },
            async: false,
            //contentType: 'application/json',
            success: function (data, status) {
                if (status == "success") {
                    if (data != null) {
                        $("#P_ReportNumber").val(data.P_ReportNumber)
                        $("#C_project").val(data.C_project)
                        $("#C_sourceID").val(data.C_sourceID)
                        $("#C_source").val(data.C_source)
                        $("#C_closeID").val(data.C_closeID)
                        $("#C_buildingID").val(data.C_buildingID)
                        $("#C_trafficID").val(data.C_trafficID)
                        $("#C_afforestID").val(data.C_afforestID)
                        $("#C_volumeID").val(data.C_volumeID)
                        $("#C_stallID").val(data.C_stallID)
                        $("#C_propertyID").val(data.C_propertyID)
                        $("#C_else").val(data.C_else)
                        $("#C_state").val(data.C_state)
                    }
                }
            },
            error: function (e) {
                layer.msg('服务器链接超时!', { icon: 2, time: 5000 });
            },
            complete: function () {

            }
        })
        //建筑公共部位的数据回填
        $.ajax({
            type: "get",
            url: ApiUrl + "api/Facility/SelectByid",
            data: { P_ReportNumber: P_ReportNumber11 },
            async: false,
            success: function (data, status) {
                if (status == "success") {
                    if (data != null) {
                        $("#F_id           ").val(data.F_id)
                        $("#P_ReportNumber ").val(data.P_ReportNumber)
                        $("#F_structureID  ").val(data.F_structureID)
                        $("#F_TypesID      ").val(data.F_TypesID)
                        $("#F_facadeID     ").val(data.F_facadeID)
                        $("#F_commonalityID").val(data.F_commonalityID)
                        $("#F_elevatorID   ").val(data.F_elevatorID)
                        $("#F_supplyID     ").val(data.F_supplyID)
                        $("#F_waterID      ").val(data.F_waterID)
                        $("#F_heatingID    ").val(data.F_heatingID)
                        $("#F_entranceID   ").val(data.F_entranceID)
                        $("#F_else         ").val(data.F_else)
                        $("#F_state        ").val(data.F_state)
                    }
                }
            },
            error: function (e) {
                layer.msg('服务器链接超时!', { icon: 2, time: 5000 });
            },
            complete: function () {

            }
        })
        //根据报告号判断抵押物区位状况有没有以前填写的数据如果有回填
        $.ajax({
            type: "get",
            url: ApiUrl + "api/Zone/selectbyid",
            data: { P_ReportNumber: P_ReportNumber11 },
            async: false,
            success: function (data, status) {
                if (status == "success") {
                    if (data != null) {
                        $("#P_ReportNumber").val(data.P_ReportNumber)
                        $("#Z_master").val(data.Z_master)
                        $("#Z_south").val(data.Z_south)
                        $("#Z_western").val(data.Z_western)
                        $("#Z_north").val(data.Z_north)
                        $("#Z_trafficID").val(data.Z_trafficID)
                        $("#Z_traffic").val(data.Z_traffic)
                        $("#Z_natureID").val(data.Z_natureID)
                        $("#Z_nature").val(data.Z_nature)
                        $("#Z_dwellingID").val(data.Z_dwellingID)
                        $("#Z_dwelling").val(data.Z_dwelling)
                        $("#Z_infrastructureID").val(data.Z_infrastructureID)
                        $("#Z_supportingID").val(data.Z_supportingID)
                        $("#Z_explain").val(data.Z_explain)
                        $("#Z_infrastructure").val(data.Z_infrastructure)
                        $("#Z_state").val(data.Z_state)
                        $("#surround").val(data.Z_surroundID)
                    }
                }
            },
            error: function (e) {
                layer.msg('服务器链接超时!', { icon: 2, time: 5000 });
            },
            complete: function () {

            }
        })
    }
   

}

